

<template>
  <div>
    <basic-container>
      <avue-crud :option="tableOption" :data="tableData" :table-loading="tableLoading" :page="page" ref="crud" @size-change="sizeChange" @current-change="currentChange" @row-click="handleClick">
        <template slot="menuLeft">
          <el-select style="width:150px !important;" v-model="cateIndex" placeholder="请选择" @change="handleList(true)">
            <el-option v-for="(item,index) in topCate" :key="index" :label="item.name" :value="item.id">
            </el-option>
          </el-select>
        </template>
        <template slot-scope="scope" slot="menu" style="width:100px">
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
/* eslint-disable */
import { mapGetters } from "vuex";
import crudMixin from '@/mixins/crud'
import options from "./options.js";
import { isNull, arr2pojo, obj2pojo, validateResponse } from "@/util/util";
import { successMsg, errorMsg } from "@/util/message"
import { field, reField } from "./field";


export default {
  name: "role",
  mixins: [crudMixin],
  components: {
  },
  data() {
    return Object.assign({}, options, {
      topCate:'',
      cateIndex:''
    })
  },
  created() {
    //初始化数据格式
    this.handleList();
  },
  watch: {},
  mounted() { },
  computed: {
  },
  props: [],
  methods: {
    handleList(init = false) {
       if (init)
      {
        this.page.currentPage = 1
      }
      this.tableLoading = true;
      let param = Object.assign({}, {
        perPage: this.page.pageSize,
        page: this.page.currentPage,
        top:this.cateIndex,
      });
      var vm = this
      this.tableData = [];
      this.page.total = 0;
      
      this.$store.dispatch('GetCategory',param).then(res => {
      this.tableLoading = false;
           if (res.data.status == 1){
              let data = res.data.result
              this.tableData = data.list.data || []
              this.topCate = data.topCate
              if (isNull(this.cateIndex)){
                 this.cateIndex = this.topCate[0].id
              }
              this.page.total = data.list.total
           }
      })
    },
  }
};
</script>
